package com.guoguo.cloudmusic.utils

import android.app.ActivityManager
import android.content.Context
import java.util.ArrayList

/**
 * 服务类
 * @author GuoGuo
 * @date 2021/12/29
 */
object ServiceUtils {
    /**
     * 判断当前service是否在运行
     */
    fun isServiceRunning(context: Context, ServiceName: String?): Boolean {
        if ("" == ServiceName || ServiceName == null) return false
        val myManager = context
            .getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
        val runningService = myManager
            .getRunningServices(30) as ArrayList<ActivityManager.RunningServiceInfo>
        for (i in runningService.indices) {
            if (runningService[i].service.className
                == ServiceName
            ) {
                return true
            }
        }
        return false
    }
}